﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using PhoneApp1.Model;
using PhoneApp1.Other;
using System.Windows.Input;
namespace PhoneApp1
{
    public partial class Page1 : PhoneApplicationPage
    {
        private InputScope scope;
        public Page1()
        {
            InitializeComponent();
            this.DataContext = App.IncomeView;
            scope = new InputScope();
            InputScopeName name = new InputScopeName();
            name.NameValue = InputScopeNameValue.Number;
            scope.Names.Add(name);
        }

        private RandomGenerator rngRan = new RandomGenerator(2);
        
        private void appBarOkButton_Click(object sender, EventArgs e)
        {
            if (mInfo.Text.Length > 0)
            {
                if (mValue.Text.Length > 0)
                {
                    Income newIncomeItem = new Income
                    {
                        IncomeID="I"+ rngRan.Value,
                        IncomeName= mInfo.Text.ToString(),
                        IncomeValue=Int16.Parse(mValue.Text),
                        IncomeTime= (DateTime)mDate.Value
                    };
                    App.IncomeView.AddIncomeItems(newIncomeItem);
                    if (NavigationService.CanGoBack)
                    {
                        NavigationService.GoBack();
                    }
                }
                else
                {
                    MessageBoxResult warning = MessageBox.Show("Xin nhập đầy đủ thông tin hoặc nhập lại thông tin không hợp lệ", "Giá trị", MessageBoxButton.OK);
                }
            } 
            else
            {
                MessageBoxResult waring = MessageBox.Show("Xin nhập đầy đủ thông tin", "Nội Dung", MessageBoxButton.OK);
            }

        }

        private void appBarCancelButton_Click(object sender, EventArgs e)
        {
            if (NavigationService.CanGoBack)
                NavigationService.GoBack();
        }
    }
}